<template>
  <div class="app-container">

    <el-card style="border-radius: 10px">
      <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="100px">
        <el-form-item label="客户名称" prop="vendorName">
          <el-input
            v-model="queryParams.vendorName"
            placeholder="请输入客户名称"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item label="物料名称" prop="itemName">
          <el-input
            v-model="queryParams.itemName"
            placeholder="请输入物料名称"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item label="物料类型名称" prop="itemTypeName">
          <el-input
            v-model="queryParams.itemTypeName"
            placeholder="请输入物料类型名称"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item>
          <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
          <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
        </el-form-item>
      </el-form>
    </el-card>

    <div style="height: 15px"></div>
    <el-card style="border-radius: 10px">
      <el-row :gutter="10" class="mb8">
        <el-col :span="1.5">
          <el-button
            type="primary"
            icon="el-icon-download"
            size="mini"
            @click="handleExport"
            v-hasPermi="['cg:order:statement:export']"
          >导出</el-button>
        </el-col>
      </el-row>

      <el-table
        v-loading="loading"
        stripe
        :data="OrderDetailsList"
      >
        <el-table-column label="采购单号"  align="center" prop="orderCode" :show-overflow-tooltip="true"/>
        <el-table-column label="供应商名称"  align="center" prop="vendorName" :show-overflow-tooltip="true"/>
        <el-table-column label="供货日期"  align="center" prop="materialDeadline" />
        <el-table-column label="物料编号"  align="center" prop="itemCode" />
        <el-table-column label="物料名称"  align="center" prop="itemName" />
        <el-table-column label="规格型号"  align="center" prop="specification" :show-overflow-tooltip="true"/>
        <el-table-column label="单位"  align="center" prop="unitOfMeasure" />
        <el-table-column label="物料分类名称"  align="center" prop="itemTypeName" />
        <el-table-column label="采购数量"  align="center" prop="quantity" />
        <el-table-column label="单价"  align="center" prop="estimatedUnitPrice" />
        <el-table-column label="总价"  align="center" prop="total" />
        <el-table-column label="状态"  align="center" prop="status">
          <template slot-scope="scope">
            <el-tag v-if="scope.row.status === 3" type="info">待确认</el-tag>
            <el-tag v-else-if="scope.row.status === 0" type="danger">采购中</el-tag>
            <el-tag v-else-if="scope.row.status === 1" >申请入库</el-tag>
            <el-tag v-else-if="scope.row.status === 2" type="success">已入库</el-tag>
          </template>
        </el-table-column>
      </el-table>

      <pagination
        v-show="total>0"
        :total="total"
        :page.sync="queryParams.pageNum"
        :limit.sync="queryParams.pageSize"
        @pagination="getList"
      />
    </el-card>
  </div>
</template>

<script>
import { listOrderLineStatement } from "@/api/mes/cg/order";


export default {
  name: "OrderDetailsStatement",
  components: {},
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 表格数据
      OrderDetailsList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        vendorName: null,
        itemName: null,
        itemTypeName: null,
      },
    };
  },
  created() {
    this.getList();
  },

  methods: {
    /** 查询产品销售退货行列表 */
    getList() {
      this.loading = true;
      listOrderLineStatement(this.queryParams).then(response => {
        this.OrderDetailsList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },

    /** 导出按钮操作 */
    handleExport() {
      this.download('/mes/cg/order/orderDetailsExport', {
        ...this.queryParams
      }, `采购订单明细报表_${new Date().getTime()}.xlsx`)
    },

  }
};
</script>
